package ModelImplementation

import (
	"math"
	"SoftwareEngineering/Model"
	"time"
)

type HourlyClassification struct {
	itsRate      float64
	itsTimeCards map[time.Time]TimeCard
}

func(h *HourlyClassification) HourlyClassification(hourlyRate float64){
	h.itsRate = hourlyRate
}

func(h *HourlyClassification) GetRate() float64{
	return h.itsRate
}

func(h *HourlyClassification) GetTimeCard(date time.Time)TimeCard{
	return h.itsTimeCards[date]
}

func(h *HourlyClassification) AddTimeCard(tc TimeCard){
	h.itsTimeCards[tc.GetDate()] = tc
}

func(h *HourlyClassification) CalculatePayForTimeCard(tc TimeCard)float64{
	hours := tc.GetHours()
	overtime := math.Max(0.0,hours-8.0)
	straightTime := hours - overtime
	return straightTime*h.itsRate+overtime*h.itsRate*1.5
}

func(h *HourlyClassification) CalculatePay(pc Model.Paycheck)float64{
	totalPay := 0.0
	
	for date := range h.itsTimeCards {
		tc := h.itsTimeCards[date]

		dt1 := pc.GetPayPeriodStartDate()
		dt2 := pc.GetPayPeriodEndDate()

		if date.After(dt1) && date.Before(dt2) {
			totalPay += h.CalculatePayForTimeCard(tc)
		}
	}

	return totalPay
}